package tolaya
{
	import com.utils.RegUtil;
	
	import flash.events.Event;
	import flash.events.HTTPStatusEvent;
	import flash.events.IOErrorEvent;
	import flash.events.SecurityErrorEvent;
	import flash.events.TimerEvent;
	import flash.filesystem.File;
	import flash.filesystem.FileMode;
	import flash.filesystem.FileStream;
	import flash.net.URLLoader;
	import flash.net.URLLoaderDataFormat;
	import flash.net.URLRequest;
	import flash.text.TextField;
	import flash.utils.Timer;
	
	import spark.components.Label;
	
	import utils.RegUtil;
	import utils.StringTool;
	
	
	public class FlashToLaya
	{
		public static var printMsg:Label;
		private var _path:String;
		private var _path2:String;
		private var _cfgStream:FileStream;
		private var _urlLoader:URLLoader;
		private var _timer:Timer;
		
		public function FlashToLaya()
		{
			_timer = new Timer(1000);
		}
		public function doLoad(path:String):void
		{
			//"C:\Users\Administrator\Desktop\ani原始\21000\bg_tiles\1.mp"
			
			_path = path;
			_path2 = path.replace(".as", "-222.as");
			
			loadData();
		}
		private function loadData():void
		{
			var request:URLRequest = new URLRequest(_path);
			_urlLoader = new URLLoader();
			_urlLoader.addEventListener(Event.COMPLETE, onComplete1);
			_urlLoader.addEventListener(IOErrorEvent.IO_ERROR, onLoadError1);
			_urlLoader.addEventListener(HTTPStatusEvent.HTTP_STATUS, onLoadError2);
			_urlLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onLoadError3);
			_urlLoader.data = null;
			_urlLoader.dataFormat = URLLoaderDataFormat.TEXT;
			_urlLoader.load(request);
			
		}
		/**
		 * 注意，以下转换，只转换logic、modules包里的内容，其它的不要转换。
		 */
		private function onComplete1(e:Event):void
		{
			_urlLoader.removeEventListener(Event.COMPLETE, onComplete1);
			_urlLoader.removeEventListener(IOErrorEvent.IO_ERROR, onLoadError1);
			_urlLoader.removeEventListener(HTTPStatusEvent.HTTP_STATUS, onLoadError2);
			_urlLoader.removeEventListener(SecurityErrorEvent.SECURITY_ERROR, onLoadError3);
			
			var content:String = (_urlLoader.data);
			if(!content){
				return;
			}
			_urlLoader.close();
			
			//文本测试
//			var label:TextField = new TextField();
//			label.text = content;
//			mytrace("文本行数：" + label.numLines);
			
//			var arr:Array = content.match(/[\u4e00-\u9fa5：，]+/g);
//			var arr:Array = content.match(/\b=| = /g);
			
			var newStr:String = content;
			//必须放在前面替换的
			newStr = newStr.replace(/protected function onClose\(e:MouseEvent/gi, "protected function onClose(e:*");
			newStr = newStr.replace(/protected function checkDragTarget\(target:Object/gi, "protected function checkDragTarget(target:*");
			newStr = newStr.replace(/protected function onDrag\(e:Event/gi, "protected function onDrag(e:* = null");
			newStr = newStr.replace(/protected function onDrag\(e:MouseEvent/gi, "protected function onDrag(e:* = null");
			if(newStr.indexOf("override public function addChild\(child:DisplayObject\):DisplayObject") != -1){
				newStr = newStr.replace(/import flash\.display\.DisplayObject;/gi, "import laya.display.Sprite;\n\timport laya.display.Node;");
				newStr = newStr.replace(/override public function addChild\(child:DisplayObject\):DisplayObject/gi, "override public function addChild(child:Node):Node");
			}
			if(newStr.indexOf("override public function removeChild\(child:DisplayObject\):DisplayObject") != -1){
				newStr = newStr.replace(/import flash\.display\.DisplayObject;/gi, "import laya.display.Sprite;\n\timport laya.display.Node;");
				newStr = newStr.replace(/override public function removeChild\(child:DisplayObject\):DisplayObject/gi, "override public function removeChild(child:Node):Node");
			}
			if(newStr.indexOf("override public function addChildAt\(child:DisplayObject, index:int\):DisplayObject") != -1){
				newStr = newStr.replace(/import flash\.display\.DisplayObject;/gi, "import laya.display.Sprite;\n\timport laya.display.Node;");
				newStr = newStr.replace(/override public function addChildAt\(child:DisplayObject, index:int\):DisplayObject/gi, "override public function addChildAt(child:Node, index:int):Node");
			}
			if(newStr.indexOf("override public function removeChildAt\(index:int\):DisplayObject") != -1){
				newStr = newStr.replace(/import flash\.display\.DisplayObject;/gi, "import laya.display.Sprite;\n\timport laya.display.Node;");
				newStr = newStr.replace(/override public function removeChildAt\(index:int\):DisplayObject/gi, "override public function removeChildAt(index:int):Node");
			}
			newStr = newStr.replace(/\/*import flash\.utils\.clearTimeout/gi, "");//import flash.utils.clearTimeout
			newStr = newStr.replace(/\/*import flash\.utils\.setTimeout/gi, "");//import flash.utils.setTimeout
			newStr = newStr.replace(/removeEventListener\(TimerEvent\.TIMER_COMPLETE,/gi, "off(Event.COMPLETE, this, ");
			newStr = newStr.replace(/addEventListener\(TimerEvent\.TIMER_COMPLETE,/gi, "on(Event.COMPLETE, this, ");
			newStr = newStr.replace(/\(TimerEvent\.TIMER,/gi, "( this,");
			newStr = newStr.replace(/:TimerEvent\)/gi, ":Event = null)");
//			newStr = newStr.replace(/\/*import com\.qixia\.core\.events\.DataEvent/gi, "");//import com.qixia.core.events.DataEvent
			newStr = newStr.replace(/com\.qixia\.core\.net\.HttpRequest/gi, "laya.net.HttpRequest");
			newStr = newStr.replace(/import flash\.net\.URLLoader/gi, "import flashdisplay.FURLLoader");
			newStr = newStr.replace(/\/*import flash\.net\.URLRequest;/gi, "");//import flash.net.URLRequest
			
			//全字替换
			newStr = newStr.replace(/com\.netease\.protobuf\./gi, "netease.protobuf.");
			newStr = newStr.replace(/flash\.utils\.IDataInput/gi, "flashdisplay.FByteArray");
			newStr = newStr.replace(/flash\.utils\.IDataOutput/gi, "flashdisplay.FByteArray");
			newStr = newStr.replace(/flash\.utils\.ByteArray/gi, "flashdisplay.FByteArray");
			newStr = newStr.replace(/\/*import flash\.utils\.IExternalizable/gi, "");//import flash\.utils\.IExternalizable
			newStr = newStr.replace(/\/*import flash\.errors\.IOError/gi, "");//import flash.errors.IOError
			newStr = newStr.replace(/:IDataInput/gi, ":FByteArray");
			newStr = newStr.replace(/:IDataOutput/gi, ":FByteArray");
			newStr = newStr.replace(/:ByteArray/gi, ":FByteArray");
			newStr = newStr.replace(/new ByteArray/gi, "new FByteArray");
			newStr = newStr.replace(/override netease.protobuf.used_by_generated_code final/gi, "override public final");
			newStr = newStr.replace(/throw new flash\.errors\.IOError\(/gi, "throw new Error(");
			newStr = newStr.replace(/\/*use namespace /gi, "//use namespace");
			newStr = newStr.replace(/netease\.protobuf\.ReadUtils\.read_TYPE_INT32,/gi, "Handler.create(this, ReadUtils.read_TYPE_INT32),");
			newStr = newStr.replace(/netease\.protobuf\.ReadUtils\.read_TYPE_INT64,/gi, "Handler.create(this, ReadUtils.read_TYPE_INT64),");
			newStr = newStr.replace(/morn\.core\.handlers\.Handler/gi, "laya.utils.Handler");
			newStr = newStr.replace(/flash\.display\.DisplayObjectContainer/gi, "laya.display.Sprite");
			newStr = newStr.replace(/flash\.display\.InteractiveObject/gi, "laya.display.Sprite");
			newStr = newStr.replace(/flash\.display\.Sprite/gi, "laya.display.Sprite");
			newStr = newStr.replace(/DisplayObjectContainer/gi, "Sprite");
			newStr = newStr.replace(/flash\.display\.DisplayObject/gi, "laya.display.Sprite");
			
			newStr = newStr.replace(/IDisplayObject/gi, "IDisplayzxkObject");//代替
			newStr = newStr.replace(/DisplayObject/gi, "Sprite");
			newStr = newStr.replace(/IDisplayzxkObject/gi, "IDisplayObject");//还原
			
			newStr = newStr.replace(/:Event\)/gi, ":Event = null)");
			newStr = newStr.replace(/:MouseEvent\)/gi, ":Event = null)");
			newStr = newStr.replace(/:MouseEvent \)/gi, ":Event = null)");
			newStr = newStr.replace(/:KeyboardEvent\)/gi, ":Event = null)");
			newStr = newStr.replace(/flash\.text\.TextFormatAlign/gi, "greensock.layout.AlignMode");
			newStr = newStr.replace(/TextFormatAlign/gi, "AlignMode");
			newStr = newStr.replace(/dispatchEvent\( new MouseEvent/g, "dispatchEvent(new NewEvent");
			newStr = newStr.replace(/dispatchEvent\(new MouseEvent/g, "dispatchEvent(new NewEvent");
			newStr = newStr.replace(/dispatchEvent\(new Event/gi, "dispatchEvent(new NewEvent");
			newStr = newStr.replace(/:MouseEvent/gi, ":Event");
			newStr = newStr.replace(/flash\.text\.TextFormat/gi, "flashtext.TextFormat");
			newStr = newStr.replace(/LinkButton/gi, "Button");
			
			//date日期，时间
			newStr = newStr.replace(/:Date/gi, ":FDate");
			newStr = newStr.replace(/new Date\(/gi, "new FDate(");
			
			newStr = newStr.replace(/\.setScrollPos/gi, ".scrollTo");
			newStr = newStr.replace(/Tab\.VERTICAL/gi, "EnumCommon.VERTICAL");
			newStr = newStr.replace(/RadioGroup\.VERTICAL/gi, "EnumCommon.VERTICAL");
			newStr = newStr.replace(/Tab\.HORIZENTAL/gi, "EnumCommon.HORIZENTAL");
			newStr = newStr.replace(/RadioGroup\.HORIZENTAL/gi, "EnumCommon.HORIZENTAL");
			newStr = newStr.replace(/new Tab\(/gi, "SimpleUtils.createTab(");
			newStr = newStr.replace(/new Image\(/gi, "SimpleUtils.createImage(");
			newStr = newStr.replace(/new BitmapData\(/gi, "SimpleUtils.createBitmapData(");
			newStr = newStr.replace(/:BitmapData/gi, ":Texture");
			newStr = newStr.replace(/startDrag\(/gi, "startDrag2(");
			newStr = newStr.replace(/uide\.show\(/gi, "uide.show2(");
			newStr = newStr.replace(/uide1\.show\(/gi, "uide1.show2(");
			newStr = newStr.replace(/Button\.PRESS/gi, "Event.CLICK");
			newStr = newStr.replace(/App\.render\.callLater\(/gi, "App.timer.doTimeOnce(_this, 1, ");
			newStr = newStr.replace(/uint\.MAX_VALUE/gi, "EnumCommon.UINT_MAX_VALUE");
			newStr = newStr.replace(/int\.MAX_VALUE/gi, "EnumCommon.INT_MAX_VALUE");
			newStr = newStr.replace(/InteractiveObject/gi, "Sprite");
			newStr = newStr.replace(/ArgumentError/gi, "Error");
			newStr = newStr.replace(/:DataEvent/gi, ":*");
			newStr = newStr.replace(/\/*import flash\.net\.URLVariables/gi, "");//import flash.net.URLVariables
			newStr = newStr.replace(/URLVariables/gi, "Object");
			newStr = newStr.replace(/:URLLoader/gi, ":FURLLoader");
			newStr = newStr.replace(/new URLLoader\(/gi, "new FURLLoader(");
			newStr = newStr.replace(/new URLRequest\(/gi, "String(");
			newStr = newStr.replace(/App\.asset\.getBaseBitmapData\(/gi, "App.getTexture(");
			newStr = newStr.replace(/App\.asset\.destroyClips\(/gi, "App.clearTexture(");
			newStr = newStr.replace(/\.stroke = /gi, ".stroke2 = ");
			newStr = newStr.replace(/\.callChangeScroll\(/gi, ".refresh(");
			newStr = newStr.replace(/morn\.core\.utils\.BitmapUtils;/gi, "com.qixia.core.utils.BitmapUtils;");
			newStr = newStr.replace(/flash\.system\.Capabilities;/gi, "flashutils.Capabilities;");
			newStr = newStr.replace(/flash\.net\.SharedObject;/gi, "com\.qixia\.core\.components\.utils\.LocalSave;");
			newStr = newStr.replace(/SharedObject\.getLocal\(/gi, "new LocalSave(");
			newStr = newStr.replace(/:SharedObject/gi, ":LocalSave");
			newStr = newStr.replace(/as Bitmap\)\.bitmapData;/gi, ");");
			newStr = newStr.replace(/\.bitmapData = /gi, ".texture = ");
			newStr = newStr.replace(/\.scale = /gi, ".scaleXY = ");
			newStr = newStr.replace(/\.btnLabel/gi, ".text");
			newStr = newStr.replace(/\.textField\.setSelection\(/gi, ".setSelection(");
			newStr = newStr.replace(/Styles\.fontName/gi, "QXConfig.defaultFont");
			newStr = newStr.replace(/QXConfig\.stage\.getObjectsUnderPoint\(/gi, "SimpleUtils.getObjectsUnderPoint(QXConfig.stage, ");
			newStr = newStr.replace(/QXConfig\.getVersionUrl\(/gi, "QXConfig.getResVersionUrl(");
//			newStr = newStr.replace(/_FROM_STAGE/gi, "");
//			newStr = newStr.replace(/_TO_STAGE/gi, "");
			newStr = newStr.replace(/visible2/gi, "visible");
			newStr = newStr.replace(/URLRequestMethod\.GET/gi, "\"get\"");
			newStr = newStr.replace(/URLRequestMethod\.POST/gi, "\"post\"");
			newStr = newStr.replace(/\.scrollBarSkin =/gi, ".skin =");
			newStr = newStr.replace(/\.scrollBarSkin =/g, ".skin =");
			newStr = newStr.replace(/IEventDispatcher\(/g, "(");
			newStr = newStr.replace(/\.setHours\(/g, ".setHours2(");
			newStr = newStr.replace(/\/*\[ArrayElementType\(/g, "//[ArrayElementType(");
			newStr = newStr.replace(/\.stopImmediatePropagation/g, ".stopPropagation");
			
			//MouseEnabled,MouseChildren处理
			newStr = newStr.replace(/mouseEnabled /g, "flashMouseEnabled ");
			newStr = newStr.replace(/mouseEnabled;/g, "flashMouseEnabled;");
			newStr = newStr.replace(/mouseChildren /g, "flashMouseChildren ");
			newStr = newStr.replace(/mouseChildren;/g, "flashMouseChildren;");
			
			//int, uint转换
			newStr = newStr.replace(/new int\(\)/g, "0");
			newStr = newStr.replace(/\buint\(/g, "myparseUint(");
			newStr = newStr.replace(/\bint\(/g, "myparseInt(");
			if(newStr.indexOf(" interface ") == -1){
				newStr = newStr.replace(/:int;/g, ":int = 0;");
			}
			
			
			//各种parent,removeChild对应转换
			newStr = newStr.replace(/\bparent\b/g, "parent2");
//			newStr = newStr.replace(/\.removeChildAt\(/g, ".removeChildAt2(");
//			newStr = newStr.replace(/\baddChild\b/g, "addChild2");
			
			//getRect处理
			newStr = newStr.replace(/function getRect\(/gi, "function getRect2\(");
			newStr = newStr.replace(/function getBounds\(/gi, "function getBounds2(");
			newStr = newStr.replace(/.getRect\(/gi, ".getRect2\(");
			newStr = newStr.replace(/.getBounds\(/gi, ".getBounds2(");
			
			//tag调用处理
			newStr = newStr.replace(/\.tag /gi, "['tag'] ");
			newStr = newStr.replace(/\.tag\)/gi, "['tag'])");
			newStr = newStr.replace(/\.tag;/gi, "['tag'];");
			
			
			//Stat性能显示
			newStr = newStr.replace(/import com\.qixia\.core\.components\.utils\.Stats;/gi, "import flashdisplay.Stats;");
			newStr = newStr.replace(/QXConfig\.stage\.addChild\(_stats\);/gi, "_stats.show();");
			newStr = newStr.replace(/_stats\.removeFromParent\(\);/gi, "_stats.hide();");
			
			//常量替代
			newStr = newStr.replace(/Button\.EFFECT_3/gi, "EnumCommon.BUTTON_EFFECT_3");
			newStr = newStr.replace(/Button\.RED_TYPE1/gi, "EnumCommon.BUTTON_RED_TYPE1");
			newStr = newStr.replace(/Button\.RED_TYPE3/gi, "EnumCommon.BUTTON_RED_TYPE3");
			
			//原生Timer
			newStr = newStr.replace(/import flash\.events\.TimerEvent/gi, "import laya.events.Event");
			newStr = newStr.replace(/flash\.utils\.Timer/gi, "flashdisplay.FTimer");
			newStr = newStr.replace(/:Timer/gi, ":FTimer");
			newStr = newStr.replace(/new Timer\(/gi, "new FTimer(");
			newStr = newStr.replace(/\/*import flash\.utils\.getTimer/gi, "");//import flash.utils.getTimer
			
			if(newStr.indexOf("new LoginResLoader2(_this") != -1){
				newStr = newStr.replace(/new LoginResLoader2\(/gi, "new LoginResLoader2(_this, ");
			}
			if(newStr.indexOf("\.setURL\(_this") == -1){
				newStr = newStr.replace(/\.setURL\(/gi, ".setURL(_this, ");
			}
				
			//原生System
			if(newStr.indexOf("flashdisplay\.FSystem") == -1){
				newStr = newStr.replace(/import flash\.system\.System/gi, "import flashdisplay.FSystem");
				newStr = newStr.replace(/System\.privateMemory/gi, "FSystem.privateMemory");
				newStr = newStr.replace(/System\.setClipboard/gi, "FSystem.setClipboard");
			}	
			//奇侠自定义Text,BaseTextField
			if(newStr.indexOf("com.qixia.core.components.game.FText") == -1){
//				newStr = newStr.replace(/com\.core\.components\.game\.Text/gi, "com.qixia.core.components.game.FText");
				newStr = newStr.replace(/com\.qixia\.core\.components\.game\.Text/gi, "com.qixia.core.components.game.FText");
				newStr = newStr.replace(/:Text;/gi, ":FText;");
				newStr = newStr.replace(/:Text /gi, ":FText ");
				newStr = newStr.replace(/:Text\)/gi, ":FText)");
				newStr = newStr.replace(/BaseTextField/gi, "FText");
				newStr = newStr.replace(/new Text\(/gi, "new FText(");
				newStr = newStr.replace(/extends Text/gi, "extends FText");
				newStr = newStr.replace(/extends FTextArea/gi, "extends TextArea");//还原。
				
				newStr = newStr.replace(/\):TextFormat/gi, "):zxkTextFormat");//替代
				newStr = newStr.replace(/\):Texture/gi, "):zxkTexture");//替代
				newStr = newStr.replace(/\):Text/gi, "):FText");
				newStr = newStr.replace(/<Text>/gi, "<FText>");
				newStr = newStr.replace(/\):zxkTextFormat/gi, "):TextFormat");//还原。
				newStr = newStr.replace(/\):zxkTexture/gi, "):Texture");//还原。
				
				newStr = newStr.replace(/com\.core\.components\.base\.FText/gi, "com.qixia.core.components.game.FText");
			}
			newStr = newStr.replace(/com\.qixia\.core\.components\.base\.FText/gi, "com.qixia.core.components.game.FText");
			
			//原生ColorMatrixFilter
			newStr = newStr.replace(/flash\.filters\.ColorMatrixFilter/gi, "laya.filters.ColorFilter");
			newStr = newStr.replace(/ColorMatrixFilter/gi, "ColorFilter");
			
			//包目录替换
			newStr = newStr.replace(/flash\.geom\.Rectangle/gi, "laya.maths.Rectangle");
			newStr = newStr.replace(/flash\.geom\.Point/gi, "laya.maths.Point");
			newStr = newStr.replace(/flash\.display\.Stage/gi, "laya.display.Stage");
			newStr = newStr.replace(/flash\.ui\.Keyboard/gi, "laya.events.Keyboard");
			newStr = newStr.replace(/flash\.geom\.Matrix/gi, "laya.maths.Matrix");
			newStr = newStr.replace(/morn\.core\.components\./gi, "laya.ui.");
			newStr = newStr.replace(/import ui\./gi, "import qxui.mobile.");
			newStr = newStr.replace(/MouseEvent\./gi, "Event.");
			newStr = newStr.replace(/KeyboardEvent\./gi, "Event.");
			newStr = newStr.replace(/new Handler\(\)/gi, "QXHandler.create(_this, null)");
			newStr = newStr.replace(/new Handler\(/gi, "QXHandler.create(_this, ");
			newStr = newStr.replace(/\.appendText\(/gi, ".text += (");
			newStr = newStr.replace(/import com\.qixia\.core\.utils\.b64\.Base64Decoder;/gi, "import flashutils.Base64Decoder;");
			newStr = newStr.replace(/\/*import flash\.display\.Bitmap;/gi, "");//import flash.display.Bitmap;
			newStr = newStr.replace(/import flash\.display\.Graphics;/gi, "import laya.display.Graphics;");
			newStr = newStr.replace(/import flash\.events\.FocusEvent;/gi, "import flashevents.FEvent;");
			newStr = newStr.replace(/import flash\.net\.FileReference;/gi, "import flashutils.FileReference;");
			newStr = newStr.replace(/import flash\.geom\.ColorTransform;/gi, "import flashgeom.ColorTransform;");
			newStr = newStr.replace(/import flash\.external\.ExternalInterface;/gi, "import flashexternal.ExternalInterface;");
			newStr = newStr.replace(/import flash\.ui\.MouseCursor;/gi, "import flashutils.MouseCursor;");
			newStr = newStr.replace(/import flash\.events\.EventDispatcher;/gi, "import flashevents.FEventDispatcher;");
			newStr = newStr.replace(/\/*import flash\.utils\.Endian;/gi, "");//import flash.utils.Endian;
			newStr = newStr.replace(/\/*import flash\.events\.IEventDispatcher;/g, "");//import flash.events.IEventDispatcher;
			
			//包目录之后的
			newStr = newStr.replace(/RadioButton/gi, "Radio");
			newStr = newStr.replace(/FocusEvent\.FOCUS_IN/gi, "FEvent.FOCUS_IN");
			newStr = newStr.replace(/FocusEvent\.FOCUS_OUT/gi, "FEvent.FOCUS_OUT");
			newStr = newStr.replace(/:FocusEvent/gi, ":Event = null");
			newStr = newStr.replace(/laya\.ui\.Container;/gi, "flashdisplay.FSprite;");
			newStr = newStr.replace(/:Container/gi, ":FSprite");
			newStr = newStr.replace(/new Container\(/gi, "new FSprite(");
			newStr = newStr.replace(/extends EventDispatcher/gi, "extends FEventDispatcher");
			
			//event处理
			newStr = newStr.replace(/import flash\.events\.Event/gi, "import laya.events.Event");
			newStr = newStr.replace(/import flash\.events\.IOErrorEvent/gi, "import laya.events.Event");
			newStr = newStr.replace(/import flash\.events\.MouseEvent/gi, "import laya.events.Event");
			newStr = newStr.replace(/import flash\.events\.KeyboardEvent/gi, "import laya.events.Event");
			newStr = newStr.replace(/import flash\.events\.TextEvent/gi, "import laya.events.Event");
			newStr = newStr.replace(/import flash\.display\.BitmapData/gi, "import laya.resource.Texture");
			newStr = newStr.replace(/public function show\(data:Object/gi, "public function show(data:*");
			newStr = newStr.replace(/public function updatePanel\(data:Object/gi, "public function updatePanel(data:*");
			newStr = newStr.replace(/:Dictionary = Application.clientDataConfig/gi, ":Object = Application.clientDataConfig");
			newStr = newStr.replace(/IOErrorEvent.IO_ERROR/gi, "Event.ERROR");
			newStr = newStr.replace(/:IOErrorEvent/gi, ":Event");
			newStr = newStr.replace(/Event\.ACTIVATE/gi, "EnumCommon.Event_ACTIVATE");
			newStr = newStr.replace(/Event\.DEACTIVATE/gi, "EnumCommon.Event_DEACTIVATE");
			
			newStr = newStr.replace(/TextEvent/gi, "Event");
			
			//奇侠handler转换
			if(newStr.indexOf("import com\.qixia\.core\.utils\.LayaHandler;") != -1){
				newStr = newStr.replace(/import com\.qixia\.core\.utils\.LayaHandler;/g, "import laya.utils.Handler;");
				newStr = newStr.replace(/:LayaHandler/g, ":Handler");
				newStr = newStr.replace(/as LayaHandler/g, "as Handler");
//				newStr = newStr.replace(/YYHandler\.create/g, "QXHandler\.create");
			}
			if(newStr.indexOf("flash\.filters\.GlowFilter") != -1){
				newStr = newStr.replace(/flash\.filters\.GlowFilter/gi, "laya.filters.GlowFilter");
				newStr = newStr.replace(/new GlowFilter\(/gi, "SimpleUtils.createGlowFilter(");
			}
			if(newStr.indexOf("morn\.core\.events\.UIEvent") != -1){
				newStr = newStr.replace(/morn\.core\.events\.UIEvent/gi, "laya.events.Event");
				newStr = newStr.replace(/:UIEvent\)/gi, ":* = null)");
				newStr = newStr.replace(/:UIEvent /gi, ":* ");
				newStr = newStr.replace(/UIEvent\.IMAGE_LOADED/gi, "Event.LOADED");
				newStr = newStr.replace(/new UIEvent\(/gi, "new NewEvent(");
			}
			if(newStr.indexOf("labelStroke2") == -1){
				newStr = newStr.replace(/labelStroke/gi, "labelStroke2");
			}
			if(newStr.indexOf("\.beginFill\(") != -1){
				newStr = newStr.replace(/\.drawRect\(/gi, ".drawRect2(");
				newStr = newStr.replace(/\.drawCircle\(/gi, ".drawCircle2(");
			}
			//flash原生监听处理
			if(newStr.indexOf("hasEventListener\(_this") == -1){
				newStr = newStr.replace(/\.hasEventListener\(/g, ".hasEventListener\(_this,");
				newStr = newStr.replace(/!hasEventListener\(/g, "!hasEventListener\(_this,");
				newStr = newStr.replace(/\(hasEventListener\(/g, "(hasEventListener\(_this,");
			}
			if(newStr.indexOf("\.addEventListener\(_this") == -1){
				newStr = newStr.replace(/\.addEventListener\(/gi, ".addEventListener\(_this,");
			}
			newStr = newStr.replace(/\.addEventListener\(_this, this,/gi, ".addEventListener\(_this,");//修正
			
			if(newStr.indexOf("\taddEventListener\(_this") == -1){
				newStr = newStr.replace(/\taddEventListener\(/gi, "\taddEventListener\(_this,");
			}
			if(newStr.indexOf("\.removeEventListener\(_this") == -1){
				newStr = newStr.replace(/\.removeEventListener\(/gi, ".removeEventListener\(_this,");
			}
			newStr = newStr.replace(/\.removeEventListener\(_this, this,/gi, ".removeEventListener\(_this,");
			
			if(newStr.indexOf("\tremoveEventListener\(_this") == -1){
				newStr = newStr.replace(/\tremoveEventListener\(/gi, "\tremoveEventListener\(_this,");
			}
			if(newStr.indexOf("\.addKeyDownEventListener\(_this") == -1){
				newStr = newStr.replace(/\.addKeyDownEventListener\(/gi, ".addKeyDownEventListener(_this, ");
			}
			if(newStr.indexOf("\.addKeyUpEventListener\(_this") == -1){
				newStr = newStr.replace(/\.addKeyUpEventListener\(/gi, ".addKeyUpEventListener(_this, ");
			}
			if(newStr.indexOf("\.removeKeyDownEventListener\(_this") == -1){
				newStr = newStr.replace(/\.removeKeyDownEventListener\(/gi, ".removeKeyDownEventListener(_this, ");
			}
			if(newStr.indexOf("\.removeKeyUpEventListener\(_this") == -1){
				newStr = newStr.replace(/\.removeKeyUpEventListener\(/gi, ".removeKeyUpEventListener(_this, ");
			}
			if(newStr.indexOf("setTimeout\(_this") == -1){
				newStr = newStr.replace(/setTimeout\(/gi, "setTimeout(_this, ");
			}
			if(newStr.indexOf("clearTimeout\(_this") == -1){
				newStr = newStr.replace(/clearTimeout\(/gi, "clearTimeout(_this, ");
			}
			//TimeCenter
			if(newStr.indexOf("App\.timer\.doTimeOnce\(_this") == -1){
				newStr = newStr.replace(/App\.timer\.doTimeOnce\(/gi, "App.timer.doTimeOnce(_this,");
			}
			if(newStr.indexOf("App\.timer\.doTimeLoop\(_this") == -1){
				newStr = newStr.replace(/App\.timer\.doTimeLoop\(/gi, "App.timer.doTimeLoop(_this,");
			}
			if(newStr.indexOf("App\.timer\.doFrameOnce\(_this") == -1){
				newStr = newStr.replace(/App\.timer\.doFrameOnce\(/gi, "App.timer.doFrameOnce(_this,");
			}
			if(newStr.indexOf("App\.timer\.doFrameLoop\(_this") == -1){
				newStr = newStr.replace(/App\.timer\.doFrameLoop\(/gi, "App.timer.doFrameLoop(_this,");
			}
			if(newStr.indexOf("App\.timer\.serverTimeEnd\(_this") == -1){
				newStr = newStr.replace(/App\.timer\.serverTimeEnd\(/gi, "App.timer.serverTimeEnd(_this,");
			}
			if(newStr.indexOf("App\.timer\.clearTimer\(_this") == -1){
				newStr = newStr.replace(/App\.timer\.clearTimer\(/gi, "App.timer.clearTimer(_this,");
			}
			//TweenLite,TweenMax
			if(newStr.indexOf("TweenLite\.delayedCall\(_this") == -1){
				newStr = newStr.replace(/TweenLite\.delayedCall\(/gi, "TweenLite.delayedCall(_this, ");
			}
			if(newStr.indexOf("TweenMax\.delayedCall\(_this") == -1){
				newStr = newStr.replace(/TweenMax\.delayedCall\(/gi, "TweenMax.delayedCall(_this, ");
			}
			if(newStr.indexOf("caller:_this, onComplete:") == -1){
				if(newStr.indexOf("onComplete:") != -1){
					newStr = newStr.replace(/onComplete:/g, "caller:_this, onComplete:");
				}
			}
			if(newStr.indexOf("caller:_this, \"onComplete\":") == -1){
				if(newStr.indexOf("\"onComplete\":") != -1){
					newStr = newStr.replace(/\"onComplete\":/g, "caller:_this, onComplete:");
				}
			}
			if(newStr.indexOf("caller:_this, onUpdate:") == -1){
				if(newStr.indexOf("onUpdate:") != -1){
					newStr = newStr.replace(/onUpdate:/g, "caller:_this, onUpdate:");
				}
			}
			if(newStr.indexOf("caller:_this, \"onUpdate\":") == -1){
				if(newStr.indexOf("\"onUpdate\":") != -1){
					newStr = newStr.replace(/\"onUpdate\":/g, "caller:_this, onUpdate:");
				}
			}
			
			
			if(newStr.indexOf("ZLinkButton") == -1){
				newStr = newStr.replace(/morn\.core\.components\.LinkButton/gi, "zxk.ZLinkButton");
				newStr = newStr.replace(/:LinkButton/gi, ":ZLinkButton");
				newStr = newStr.replace(/new LinkButton\(/gi, "new LinkButton(");
			}
			
//			if(_path.indexOf("com\\game\\container\\") != -1){
//				newStr = newStr.replace(/:Dictionary/gi, ":Object");
//				newStr = newStr.replace(/new Dictionary\(/gi, "new Object(");
//			}
			if(_path.indexOf("\\DataConfigUtils\.as") != -1){
				newStr = newStr.replace(/onFinish:Function/gi, "onFinish:Handler");
				var index1:int = newStr.indexOf("{");
				var str1:String = newStr.substring(0, index1+1);
				var str2:String = newStr.substring(index1+1);
				newStr = str1 + "\n\timport laya.utils.Handler;" + str2;
			}
			else if(_path.indexOf("MessagePool\.as") != -1){
				newStr = newStr.replace(/messages:Dictionary = new Dictionary\(\)/gi, "messages:Object = new Object()");
				newStr = newStr.replace(/messageClass:Class/gi, "msgClass:Class");
				newStr = newStr.replace(/messageClass: Class/gi, "msgClass:Class");
				newStr = newStr.replace(/messageClass: Class/gi, "msgClass:Class");
				newStr = newStr.replace(/=messageClass;/g, "=msgClass;");
				newStr = newStr.replace(/messageClass\[messageClass\]/g, "messageClass[msgClass]");
			}
			
			//补充，调整，修复
			newStr = newStr.replace(/com.modules.tip.TipData/gi, "com.core.tip.TipData");
			newStr = newStr.replace(/com.modules.tip.QXTipManager/gi, "com.core.tip.QXTipManager");
			newStr = newStr.replace(/onstartDrag2\(/gi, "onStartDrag(");
			
			
			//Dictionary的集中处理
			if(_path.indexOf("com\\game\\data\\container") != -1 || _path.indexOf("com\\game\\container") != -1){
				newStr = newStr.replace(/\/*import flashutils\.FDictionary;/gi, "");//import laya.utils.Dictionary;
				newStr = newStr.replace(/\/*import flash\.utils\.Dictionary;/gi, "");//import laya.utils.Dictionary;
				newStr = newStr.replace(/Dictionary/gi, "Object");
				newStr = newStr.replace(/, onFinish\)/gi, ", Handler.create(this,onFinish))");
			}
			else{
				newStr = newStr.replace(/flashutils\.FDictionary/gi, "laya.utils.Dictionary");
				newStr = newStr.replace(/flash\.utils\.Dictionary/gi, "laya.utils.Dictionary");
				
				if(_path.indexOf("AdvancePanelRedPoint.as") != -1){
					trace("崩溃调试");
				}
				newStr = getValueStr(newStr);
				newStr = getForStr(newStr);
				newStr = getCmdRegisterStr(newStr);
				newStr = getCmdRemoveStr(newStr);
				newStr = getLayaUIStr(newStr, "png");
				newStr = getLayaUIStr(newStr, "jpg");
				newStr = getSortOnStr(newStr);
				newStr = getStaticThisStr(newStr);
				newStr = getStaticThisStr2(newStr);
				newStr = getAsClassStr(newStr);
				newStr = getMaskStr(newStr);
				newStr = getIsObjectStr(newStr);
			}
			
			//末尾检测
			if(newStr.indexOf("Handler.create") != -1){
				if(newStr.indexOf("import laya.utils.Handler;") == -1){
					index1 = newStr.indexOf("{");
					str1 = newStr.substring(0, index1+1);
					str2 = newStr.substring(index1+1);
					newStr = str1 + "\n\timport laya.utils.Handler;" + str2;
				}
			}
				
			
			if(newStr == content){
				//不需要操作
				return;
			}
			
			var rootFile:File = new File();
			var fl:File = rootFile.resolvePath(_path2);
			
			try
			{
				_cfgStream = new FileStream();
				_cfgStream.open(fl, FileMode.WRITE);
				_cfgStream.writeUTFBytes(newStr);
				_cfgStream.close();
				
				_timer.addEventListener(TimerEvent.TIMER, onTimer2);
				_timer.start();
			}
			catch(e:Error)
			{
				throw new Error(e.getStackTrace());
			}
		}
		
		
		/**
		 * 重新检查，caller域，修正静态域的调用
		 */
		private function getStaticThisStr2(newStr:String):String
		{
			var index1:int = newStr.indexOf("caller:_this,");
			while(index1 != -1){
				var functionIndex:int = newStr.lastIndexOf(" function ", index1);
				var staticIndex:int = newStr.indexOf(" static ", functionIndex - 10);
				if(staticIndex != -1 && staticIndex < functionIndex){//说明是静态函数
					var lineIndex:int = newStr.indexOf(",", index1);
					var lineStr:String = newStr.substring(index1, lineIndex);//这一段的字符串
					
					var str1:String = newStr.substring(0, index1);
					var str2:String = newStr.substring(lineIndex);
					
					lineStr = "caller:_thisStatic";
					
					newStr = str1 + lineStr + str2;
					
					index1 = newStr.indexOf("caller:_this,", index1+lineStr.length);
				}
				else{
					index1 = newStr.indexOf("caller:_this,", newStr.indexOf("}", index1));
				}
			}
			
			return newStr;
		}
		
		/**
		 * 搜索" as "这类强制转换，对于转换后赋值的，需要检查逻辑。想办法做到转换。 as Array, as Number, as int, as String，不转，其它引用类要转。
		 */
		private function getAsClassStr(newStr:String):String
		{
			// = ,return ,(,
			var index1:int = newStr.indexOf(" as ");
			while(index1 != -1){
				//data as Vector.<Q_transferExpandBean>，这类情况不转换
				if(newStr.indexOf(" as Vector") == index1){
					index1 = newStr.indexOf(" as ", index1+10);
					continue;
				}
				
				//检查该行，是否是赋值作用，是赋值才转换。
				var lineIndex:int = newStr.lastIndexOf("\n", index1);
				var lineIndex3:int = newStr.indexOf("\r", index1);
				if(lineIndex == -1){
					lineIndex = lineIndex3;
				}
				if(lineIndex3 == -1){
					lineIndex3 = lineIndex;
				}
				lineIndex = Math.min(lineIndex, lineIndex3);
				var lineStr:String = newStr.substring(lineIndex, index1);
				if(lineStr.indexOf(" = ") == -1){
					index1 = newStr.indexOf(" as ", index1+5);
					continue;
				}
				
				var lineIndex:int = newStr.indexOf(")", index1);
				var lineIndex2:int = newStr.indexOf(";", index1);
				var lineIndex3:int = newStr.indexOf(":", index1);
				if(lineIndex3 != -1 && lineIndex != -1){
					lineIndex = Math.min(lineIndex, lineIndex3);
				}
				if(lineIndex2 != -1 && lineIndex != -1){
					lineIndex = Math.min(lineIndex, lineIndex2);
				}
				
				var char:String = newStr.substring(lineIndex, lineIndex + 1);
				var char2:String = newStr.substring(lineIndex, lineIndex + 2);
				if(char == ")" || char2 == " )"){
					var temp1:int = index1;
					var temp2:int = index1;
					while(true){
						var leftIndex:int = newStr.lastIndexOf("(", temp1);
						var rightIndex:int = newStr.lastIndexOf(")", temp2);
						if(leftIndex > rightIndex || rightIndex == -1){
							break;
						}
						else{
							temp1 = leftIndex - 1;
							temp2 = rightIndex - 1;
						}
					}
					var str1:String = newStr.substring(0, leftIndex+1);
					var str2:String = newStr.substring(lineIndex);
					var lineStr:String = newStr.substring(leftIndex+1, lineIndex);
					lineStr = getIntStr(lineStr);
					lineStr = "SimpleUtils.asTo(" + lineStr + ")";
					lineStr = lineStr.replace(" as ", ", ");
					
					newStr = str1 + lineStr + str2;
				}
				else if(char == ";" || char2 == " ;"){
					leftIndex = newStr.lastIndexOf(" = ", index1);
					var leftIndex2:int = newStr.lastIndexOf("//", index1);
					if(leftIndex < leftIndex2){
						leftIndex = leftIndex2;
					}
					
					var str1:String = newStr.substring(0, leftIndex+3);
					var str2:String = newStr.substring(lineIndex);
					var lineStr:String = newStr.substring(leftIndex+3, lineIndex);
					lineStr = getIntStr(lineStr);
					lineStr = "SimpleUtils.asTo(" + lineStr + ")";
					lineStr = lineStr.replace(" as ", ", ");
					
					newStr = str1 + lineStr + str2;
				}
				else if(char == ":" || char2 == " :"){
					leftIndex = newStr.lastIndexOf(" ? ", index1);
					
					var str1:String = newStr.substring(0, leftIndex+3);
					var str2:String = newStr.substring(lineIndex);
					var lineStr:String = newStr.substring(leftIndex+3, lineIndex);
					lineStr = getIntStr(lineStr);
					lineStr = "SimpleUtils.asTo(" + lineStr + ")";
					lineStr = lineStr.replace(" as ", ", ");
					
					newStr = str1 + lineStr + str2;
				}
				else{
					lineStr = "^_^";
				}
				
				index1 = newStr.indexOf(" as ", index1+lineStr.length);
			}
			
			return newStr;
		}
		
		private function getIntStr(lineStr:String):String
		{
			lineStr = lineStr.replace(/ as StringPromptPanel/g, " as xxPromptPanel");
			
			lineStr = lineStr.replace(/ as String/g, " as \"String\"");
			lineStr = lineStr.replace(/ as String/g, " as \"String\"");
			
			lineStr = lineStr.replace(/ as xxPromptPanel/g, " as StringPromptPanel");
			
			lineStr = lineStr.replace(/ as int/g, " as \"int\"");
			lineStr = lineStr.replace(/ as int/g, " as \"int\"");
			
			lineStr = lineStr.replace(/ as uint/g, " as \"uint\"");
			lineStr = lineStr.replace(/ as uint/g, " as \"uint\"");
			
			lineStr = lineStr.replace(/ as Number/g, " as \"Number\"");
			lineStr = lineStr.replace(/ as Number/g, " as \"Number\"");
			
			return lineStr;
		}
		
		/**
		 * 重新检查，caller域，修正静态域的调用
		 */
		private function getStaticThisStr(newStr:String):String
		{
			var index1:int = newStr.indexOf("\(_this,");
			while(index1 != -1){
				var functionIndex:int = newStr.lastIndexOf(" function ", index1);
				var staticIndex:int = newStr.indexOf(" static ", functionIndex - 10);
				if(staticIndex != -1 && staticIndex < functionIndex){//说明是静态函数
					var lineIndex:int = newStr.indexOf(",", index1);
					var lineStr:String = newStr.substring(index1, lineIndex);//这一段的字符串
					
					var str1:String = newStr.substring(0, index1);
					var str2:String = newStr.substring(lineIndex);
					
					lineStr = "(_thisStatic";
					
					newStr = str1 + lineStr + str2;
					
					index1 = newStr.indexOf("\(_this,", index1+lineStr.length);
				}
				else{
					index1 = newStr.indexOf("\(_this,", newStr.indexOf("}", index1));
				}
			}
			
			return newStr;
		}
		
		/**
		 * 替换flash的.sortOn()方法，h5没有sortOn
		 */
		private function getSortOnStr(newStr:String):String
		{
			var index1:int = newStr.indexOf("\.sortOn\(");
			while(index1 != -1){
				var lineIndex:int = newStr.indexOf(";", index1);
				var lineStr:String = newStr.substring(index1, lineIndex);//这一行的字符串
				
				var str1:String = newStr.substring(0, index1);
				var str2:String = newStr.substring(lineIndex);
				
				var splitIndex:int = lineStr.indexOf("\(");
				var lineStr1:String = lineStr.substring(0, splitIndex+1);
				var lineStr2:String = lineStr.substring(splitIndex+1);
				if(lineStr.indexOf("\[") != -1){
					lineStr = lineStr1 + "QXMathTools.sortFun(" + lineStr2;
				}
				else{
					lineStr = lineStr1 + "QXMathTools.sortByFlash(" + lineStr2;
				}
				lineStr = lineStr.replace("\)", "))");
				lineStr = lineStr.replace("\.sortOn\(", ".sort(");
				
				newStr = str1 + lineStr + str2;
				
				index1 = newStr.indexOf("\.sortOn\(", index1+lineStr.length);
			}
			
			newStr = newStr.replace(/\.sort\(Array\.NUMERIC\)/g, ".sort(QXMathTools.sortSmallFirst)");
			
			newStr = newStr.replace(/Array\.NUMERIC/g, "ArrayEnum.NUMERIC");
			newStr = newStr.replace(/Array\.RETURNINDEXEDARRAY/g, "ArrayEnum.RETURNINDEXEDARRAY");
			newStr = newStr.replace(/Array\.UNIQUESORT/g, "ArrayEnum.UNIQUESORT");
			newStr = newStr.replace(/Array\.DESCENDING/g, "ArrayEnum.DESCENDING");
			newStr = newStr.replace(/Array\.CASEINSENSITIVE/g, "ArrayEnum.CASEINSENSITIVE");
			
			return newStr;
		}
		
		/**
		 * 每一行不对劲的空格处理
		 */
		private function getTrimLineStr(newStr:String):String
		{
//			var index1:int = newStr.indexOf("KaiFuRankPanel.activityTypeArr.indexOf\(");
//			while(index1 != -1){
//				var lineIndex:int = newStr.indexOf("\r", index1)
//				var lineIndex2:int = newStr.lastIndexOf("\r", index1);;
//				var lineStr:String = newStr.substring(lineIndex2, lineIndex);//这一行的字符串
//				lineStr = lineStr.replace(/ /g, "zxk");
//				lineStr = lineStr.replace(/zxk/g, " ");
//				break;
//			}
//			return newStr;
			
//			newStr = newStr.replace(/ /g, "zxk66");
//			newStr = newStr.replace(/zxk66/g, "  ");
//			newStr += "//";
			return newStr;
		}
		/**
		 * mornui的png,jpg路径替换
		 */
		private function getLayaUIStr(newStr:String, typeStr:String = "png"):String
		{
			var fixStr:String = "\"" + typeStr;
			var index1:int = newStr.indexOf(fixStr + ".");
			while(index1 != -1){
				var lineIndex:int = newStr.indexOf(";", index1);
				var lineIndex2:int = newStr.indexOf("\n", index1);
				if(lineIndex2 == -1){
					lineIndex2 = lineIndex;
				}
				var lineIndex3:int = newStr.indexOf("\r", index1);
				if(lineIndex3 == -1){
					lineIndex3 = Math.max(lineIndex, lineIndex2);
				}
				lineIndex = Math.min(lineIndex, lineIndex2);
				lineIndex = Math.min(lineIndex, lineIndex3);
				
				var str1:String = newStr.substring(0, index1);
				var str2:String = newStr.substring(lineIndex+1);
				var lineStr:String = newStr.substring(index1, lineIndex+1);//这一行的字符串
				lineStr = lineStr.replace(/ as /g, "zxk");//代替
				lineStr = StringTool.trim(lineStr);
				
				var resetIndex:int = lineStr.indexOf(fixStr);
				var startFix:String = newStr.substring(index1-1, index1);
				var bIndex:int;//非字母索引
				var bStr:String;
				if(startFix == "("){
					var fenge:int = lineStr.indexOf("\"", resetIndex + 1);
					bIndex = fenge + 1;
					bStr = lineStr.substring(fenge+1, fenge+2);
					if(bStr == ")"){
						bIndex = fenge+2;
					}
					else{
						while(bStr != "," && bStr != ";" && bStr != ":" && bStr != "\n" && bStr != "\r"){
							bIndex = bIndex + 1;
							bStr = lineStr.substring(bIndex, bIndex+1);
							if(bIndex >= lineStr.length){
								break;
							}
						}
					}
					
					var fenge2:int = bIndex - 1;
					if(lineStr.substring(fenge2, fenge2+1) != ")"){
						fenge2 = bIndex;
					}
					
					var line1:String = lineStr.substring(0, fenge);
					var line2:String = lineStr.substring(fenge, fenge2);//
					var line3:String = lineStr.substring(fenge2);//
					line1 = line1.replace(/\./g, "/");
					line1 = line1.replace(fixStr, "\"mobile");
					
					line1 = getLayaSkin(line1);
					
					line1 = line1 + line2 + " + \"." + typeStr + "\"";
					lineStr = line1 + line3;
					lineStr = lineStr.replace(/zxk/g, " as ");//还原
					
					newStr = str1 + lineStr + str2;
				}
				else{
					var fenge:int = lineStr.indexOf("\"", resetIndex + 1);
					bIndex = fenge + 1;
					bStr = lineStr.substring(fenge+1, fenge+2);
					if(bStr == ")"){
						bIndex = fenge+1;
					}
					else{
						while(bStr != "," && bStr != ";" && bStr != ":" && bStr != "\n" && bStr != "\r"){
							bIndex = bIndex + 1;
							bStr = lineStr.substring(bIndex, bIndex+1);
							if(bIndex >= lineStr.length){
								break;
							}
						}
					}
					
					var line1:String = lineStr.substring(0, fenge);
					var line2:String = lineStr.substring(fenge, bIndex);
					var line3:String = lineStr.substring(bIndex);
					line1 = line1.replace(/\./g, "/");
					line1 = line1.replace(fixStr, "\"mobile");
					
					line1 = getLayaSkin(line1);
					
					line1 = line1 + line2 + " + \"." + typeStr + "\"";
					lineStr = line1 + line3;
					lineStr = lineStr.replace(/zxk/g, " as ");//还原
					
					newStr = str1 + lineStr + str2;
				}
				
				
				index1 = newStr.indexOf(fixStr + ".", index1+line1.length);
			}
			return newStr;
		}
		/**
		 * 对应AssetsToLaya的转换。
		 */
		private function getLayaSkin(path:String):String
		{
			if(path.indexOf("a_test/") == -1){
				var arr:Array = path.split("mobile/");
				var arr2:Array = arr[1].split("/");
				var newpath:String = arr[0] + "mobile/";
				for(var i:int=0; i<arr2.length; i++){
					if(i == 0){
						newpath += arr2[i] + "/";
					}
					else if(i < arr2.length-1){
						newpath += arr2[i] + "&";
					}
					else{
						newpath += arr2[i];
					}
				}
			}
			else{
				newpath = path;
			}
			return newpath;
		}
		
		/**
		 * 替换removeCommand(S2C_，消息注册的代码。
		 */
		private function getCmdRemoveStr(newStr:String):String
		{
			var index1:int = newStr.indexOf("removeCommand\(S2C_");
			while(index1 != -1){
				var lineIndex:int = newStr.indexOf(";", index1);
				var lineStr:String = newStr.substring(index1, lineIndex);//这一行的字符串
				
				if(lineStr.indexOf("QXHandler.create") == -1){
					var str1:String = newStr.substring(0, index1);
					var str2:String = newStr.substring(lineIndex);
					
					var tempStr:String = lineStr.substring(lineStr.indexOf(",")+1);
					var handlerStr:String = "QXHandler.create(_this," + tempStr + ")";
					lineStr = lineStr.replace(tempStr, handlerStr);
					
					newStr = str1 + lineStr + str2;
				}
				
				index1 = newStr.indexOf("removeCommand\(S2C_", index1+lineStr.length);
			}
			return newStr;
		}
		
		/**
		 * 替换register(S2C_，消息注册的代码。
		 */
		private function getCmdRegisterStr(newStr:String):String
		{
			var index1:int = newStr.indexOf("register\(S2C_");
			while(index1 != -1){
				var lineIndex:int = newStr.indexOf(";", index1);
				var lineStr:String = newStr.substring(index1, lineIndex);//这一行的字符串
				
				if(lineStr.indexOf("QXHandler.create") == -1){
					var str1:String = newStr.substring(0, index1);
					var str2:String = newStr.substring(lineIndex);
					
					var tempStr:String = lineStr.substring(lineStr.indexOf(",")+1);
					var handlerStr:String = "QXHandler.create(_this," + tempStr + ")";
					lineStr = lineStr.replace(tempStr, handlerStr);
					
					newStr = str1 + lineStr + str2;
				}
				
				index1 = newStr.indexOf("register\(S2C_", index1+lineStr.length);
			}
			return newStr;
		}
		
		/**
		 * 替换dictionary，for,for each的语法
		 */
		private function getForStr(newStr:String):String
		{
			var index1:int = newStr.indexOf(":Dictionary");
			while(index1 != -1){
				var varname:String = newStr.substring(newStr.lastIndexOf(" ", index1)+1, index1);
				var searchStr:String = "in " + varname;
				var index2:int = newStr.indexOf(searchStr, index1+10);
				while(index2 != -1){
					var lineIndex1:int = newStr.lastIndexOf("\n", index2);
					var lineIndex2:int = newStr.indexOf("\n", index2);
					var str3:String = newStr.substring(lineIndex1+1, lineIndex2);//这一行的字符串
					var forStr:String = str3.substring(0, str3.indexOf("("));
					forStr = StringTool.trim(forStr);
					
					var setstr:String;
					str1 = newStr.substring(0, index2);
					str2 = newStr.substring(index2+searchStr.length);
					
					if(forStr == "for"){
						setstr = searchStr + ".keys";
						if(str3.indexOf(setstr) == -1){
							newStr = str1 + setstr + str2;
						}
					}
					else if(forStr == "foreach"){
						setstr = searchStr + ".values";
						if(str3.indexOf(setstr) == -1){
							newStr = str1 + setstr + str2;
						}
					}
					
					index2 = newStr.indexOf("in " + varname, index2+2);
				}
				index1 = newStr.indexOf(":Dictionary", index1+5);
			}
			return newStr;
		}
		/**
		 * 替换dictionary赋值、取值为set,get  
		 */
		private function getValueStr(newStr:String):String
		{
			var index1:int = newStr.indexOf(":Dictionary");
			var str1:String = "";
			var str2:String = "";
			while(index1 != -1){
				trace("循环1111,index1=" + index1 + ",path=" + _path);
				var varname:String = newStr.substring(newStr.lastIndexOf(" ", index1)+1, index1);
				var index2:int = newStr.indexOf(varname+"\[", index1+10);
				while(index2 != -1){
					trace("循环2222,index2=" + index2 + ",path=" + _path);
					var usename:String = newStr.substring(index2-1, index2+varname.length);
					usename = StringTool.trimLeft(usename);
					if(usename != varname){
						if(usename.indexOf("\(") == 0){
							usename = usename.substring(1);
						}
					}
					if(usename == varname){
						var index3:int = index2+varname.length;
						//							var index4:int = newStr.indexOf("]", index3+1);
						//							var keyname:String = newStr.substring(index3+1, index4);
						
						var index5:int = newStr.indexOf("\n", index3+1);//换行索引处-后
						var index52:int = newStr.indexOf("\r", index3+1);//换行索引处
						if(index5 == -1){
							index5 = index52;
						}
						else{
							index5 = Math.min(index5, index52);
						}
						
						var index51:int = newStr.lastIndexOf("\n", index2);//换行索引处-前
						var index53:int = newStr.lastIndexOf("\r", index2);//换行索引处
						if(index51 == -1){
							index51 = index53;
						}
						else{
							index51 = Math.max(index51, index53);
						}
						var str3:String = newStr.substring(index51, index5);//这一行的字符串
						
						var index6:int = str3.lastIndexOf("++");
						var index7:int = str3.lastIndexOf("--");
						var index8:int = str3.lastIndexOf("=");
						var tagStr:String = null;
						var tempTag:String = null;
						if(index8 == -1){
							index8 = index6;
						}
						if(index8 == -1){
							index8 = index7;
						}
						if(index8 != -1){
							var index4:int = str3.lastIndexOf("\]", index8);
							if(index6 != -1 || index7 != -1){
								tagStr = str3.substring(index4+1, str3.lastIndexOf(";"));
							}
							else{
								tagStr = str3.substring(index4+1, index8+1);
							}
							tempTag = tagStr;
							tagStr = StringTool.trimLeft(tagStr);
							if(tagStr != "=" && tagStr != "+=" && tagStr != "-=" && tagStr != "++" && tagStr != "--"){
								tagStr = null;
							}
							var lineIndex1:int = str3.indexOf(varname+"\[");
							if(lineIndex1 > index8){//如果词典是在 表达式后面。说明是获取
								tagStr = null;
							}
						}
						
						if(tagStr){//说明是set方法
							str1 = newStr.substring(0, index51);
							str2 = newStr.substring(index5+1);
							
							var valueStr:String = str3.substring(index4+tempTag.length+1, str3.lastIndexOf(";"));//这一行末尾的赋值
							valueStr = StringTool.trimLeft(valueStr);
							var fix1:String = str3.substring(str3.indexOf(usename), index8);//从名字开始到 运算符结束
							var fix2:String = str3.substring(0, str3.indexOf(usename));//从这一行0开始，到名字结束。基本上就是\t空文本
							var fixStart:int = 0;
							var fixIndex:int = fix1.indexOf("\[", fixStart);
							var fixArr:Array = [];
							while(fixIndex != -1){
								fixArr.push(fixIndex);
								fixIndex = fix1.indexOf("\[", (fixIndex+1));
								trace("循环3333,fixIndex=" + fixIndex + ",path=" + _path);
								var char:String = str3.substring(fixIndex2+1, fixIndex2+2);
								if(char == "["){
									continue;
								}
								else{
									break;
								}
							}
							var setstr:String = "" + fix2 + usename;
							var valueName:String = "dicvalue"+(++dicIdCount);
							var varvalue:String = "" + fix2 + "var "+valueName+":Object" + " = " + usename;
							var fixTempIndex:int = fixArr[0] + 1;
							for(var i:int=0; i<fixArr.length-1; i++){
								if(fixArr[i] + 1 < fixTempIndex){
									i++;
									if(i>=fixArr.length-1){
										break;
									}
								}
								fixTempIndex = fix1.indexOf("\]", fixArr[i]) + 1;
								var keychild:String = fix1.substring(fixArr[i] + 1, fixTempIndex);
								setstr += ".get(" + keychild + ")";
								varvalue += ".get(" + keychild + ")";
							}
							
							keychild = fix1.substring(fixArr[i] + 1, fix1.indexOf("\]", fixArr[i]));
							
							varvalue += ".get(" + keychild + ");";
							
							if(tagStr == "++"){
								setstr += ".set(" + keychild + ", " + valueName + "+1);\n";
							}
							else if(tagStr == "--"){
								setstr += ".set(" + keychild + ", " + valueName + "-1);\n";
							}
							else if(tagStr == "+="){
								setstr += ".set(" + keychild + ", " + valueName + "+"+valueStr+");\n";
							}
							else if(tagStr == "-="){
								setstr += ".set(" + keychild + ", " + valueName + "-"+valueStr+");\n";
							}
							else{
								setstr += ".set(" + keychild + ", " + valueStr + ");\n";
							}
							newStr = str1 + varvalue + setstr + str2;
						}
						else{//说明这一行是Get方法
							var useArr:Array = [];
							lineIndex1 = str3.indexOf(varname+"\[");
							var checkCount:int = 0;
							fixArr = [];
							fixIndex = lineIndex1;
							var fixIndex2:int = 0;
							var fixIndex3:int = 0;
							var fixIndex4:int = 0;
							while(lineIndex1 != -1){
								trace("循环4444,lineIndex1=" + lineIndex1 + ",path=" + _path);
								while(checkCount <= str3.length){
									fixIndex = str3.indexOf("\[", fixIndex+1);
									fixIndex2 = str3.indexOf("\]", fixIndex);
									
									//类似这情况：activityDic[arr[i].activityId]
									fixIndex4 = fixIndex;
									fixIndex3 = str3.lastIndexOf("\[", fixIndex2);
									while(fixIndex3 > fixIndex4){
										fixIndex4 = fixIndex3;
										
										fixIndex2 = str3.indexOf("\]", fixIndex2+1);
										fixIndex3 = str3.lastIndexOf("\[", fixIndex2);
									}
									
									fixArr.push([fixIndex, fixIndex2]);
									var char:String = str3.substring(fixIndex2+1, fixIndex2+2);
									checkCount ++;
									trace("循环5555,checkCount=" + checkCount + ",path=" + _path);
									if(char == "["){
										continue;
									}
									else{
										break;
									}
								}
								
								var setstr:String = usename;
								var splitIndex:int;
								for(var i:int=0; i<fixArr.length; i++){
									var keychild:String = str3.substring(fixArr[i][0] + 1, fixArr[i][1]);
									splitIndex = fixArr[i][1];
									setstr += ".get(" + keychild + ")";
								}
								str1 = str3.substring(0, lineIndex1);
								str2 = str3.substring(splitIndex+1);
								str3 = str1 + setstr + str2;
								
								lineIndex1 = str3.indexOf(varname+"\[", lineIndex1+setstr.length);
							}
							
							str1 = newStr.substring(0, index51);
							str2 = newStr.substring(index5+1);
							newStr = str1 + str3 + str2;
						}
						
					}
					
					index2 = newStr.indexOf(varname+"\[", index2+10);
				}
				
				index1 = newStr.indexOf(":Dictionary", index1 + 10);
			}
			return newStr;
		}
		
		/**
		 * 遮罩处理
		 */
		private function getMaskStr(content:String):String
		{
			var nc:String = new String(content);
			var result:String = new String(content);
			var reg1:RegExp=/\.mask ?=.+/g;
			var reg2:RegExp=/\.mask ?= ?/g;
			RegUtil.exec(nc,reg1,function(match:String):String{
				var maskName:String = match.replace(reg2,"").replace(" ","").replace(";","");
				var maskNameReg:String = maskName+" ?= ?new BaseShape";
				var maskNR:RegExp=new RegExp(maskNameReg,"g");
				var maskNameReg2:String = maskName+"=new BaseMaskShape";
				var fb:String=result+"";
				result = result.replace(maskNR,maskNameReg2);
				if(fb!=result && result.indexOf("import com.qixia.core.components.base.BaseMaskShape")==-1) result = result.replace("import com.qixia.core.components.base.BaseShape;","import com.qixia.core.components.base.BaseShape;\r\n\timport com.qixia.core.components.base.BaseMaskShape;");
				
				maskNameReg = maskName+" ?= ?new BaseSprite";
				maskNR=new RegExp(maskNameReg,"g");
				maskNameReg2 = maskName+"=new BaseMaskSprite";
				fb = result+"";
				result = result.replace(maskNR,maskNameReg2);
				if(fb!=result && result.indexOf("import com.qixia.core.components.base.BaseMaskSprite")==-1) result = result.replace("import com.qixia.core.components.base.BaseSprite;","import com.qixia.core.components.base.BaseSprite;\r\n\timport com.qixia.core.components.base.BaseMaskSprite;");
				
				return "";
			});
			return result;
		}
		
		/**
		 * data is Object 这样的条件需要保证 data不为空
		 */
		public function getIsObjectStr(content:String):String
		{
			var reg:RegExp=/\b\w+\s+is\s+Object/g;
			content = RegUtil.exec2(content,reg,function(matchBefore:String,match:String,matchAfter:String):String{
				var varName:String = match.split(" ")[0];
				var key:String=varName+"!=null && ";
				if(matchBefore.substr(matchBefore.length-key.length)!=key){
					return key+match;
				}
				else{
					return match;
				}
			});
			return content;
		}
		
		private function onTimer2(e:TimerEvent):void
		{
			var rootFile:File = new File();
			var fnew:File = rootFile.resolvePath(_path2);
			if(fnew.exists){
				
				_timer.removeEventListener(TimerEvent.TIMER, onTimer2);
				_timer.stop();
				_timer = null;
				
				var rootFile:File = new File();
				var fold:File = rootFile.resolvePath(_path);
				
				fnew.moveTo(fold, true);
			}
		}
		
		private function onLoadError1(e:Event):void
		{
			trace("加载是失败");
		}
		private function onLoadError2(e:HTTPStatusEvent):void
		{
			if(e.status >= 400){
				trace("加载是失败2,url="+e.target.url);
			}
		}
		private function onLoadError3(e:Event):void
		{
			trace("安全沙箱错误");
		}
		
		public static var dicIdCount:int = 0;
	}
}